const path = require('path');

const isProductionEnv = (() => {
    return true;
    return process.env.NODE_DEV === 'production';
})();
const dateNow = Date.now();
const baseUrl = isProductionEnv ? `https://adams549659584.gitee.io/my-tampermonkey/` : `https://localhost:9999/`;
const layuiJsPath = isProductionEnv ? `${baseUrl}res/gm-layui/layui.js` : `${baseUrl}res/layui/layui.js`;
const layuiCssPath = isProductionEnv ? `${baseUrl}res/gm-layui/css/layui.css` : `${baseUrl}res/layui/css/layui.css`;
const layuiBasePath = isProductionEnv ? `res/gm-layui/` : `res/layui/`;
const okexHtmlTmplPath = `${baseUrl}res/okex/tmpl/`;
const getOkexWebSocketUrl = (userId) => {
    return `ws://127.0.0.1:1234/OkexLog?userId=${userId}`
};


const commonAppConfig = {
    namespace: 'test',
    version: '1.0.0',
    description: 'test',
    author: '罗君',
    match: '*://www.baidu.com/**/*',
    requires: [layuiJsPath, `${baseUrl}okex-auto-trade/js/index.js?t=${dateNow}`],
    resources: [
        {
            key: 'okexJs',
            val: `${baseUrl}okex-auto-trade/js/index.js?t=${dateNow}`
        },
    ],
    grants: ['unsafeWindow', ' GM_getResourceText', 'GM_getResourceURL', 'GM_listValues', 'GM_setValue', 'GM_getValue', 'GM_deleteValue'],
    runAt: 'document-start',
};

const userConfig = {
    isProductionEnv: isProductionEnv,
    //process.cwd() -- 当前执行node命令时候的文件夹地址
    //__dirname -- 当前模块的目录名
    basePath: process.cwd(),
    entryBasePath: path.resolve(process.cwd(), 'src'),
    outPutBasePath: path.resolve(process.cwd(), 'dist'),
    srcResPath: path.resolve(process.cwd(), 'src/res'),
    distResPath: path.resolve(process.cwd(), 'dist/res'),
    apps: ["okex-auto-trade", "kad-sync-manage"],
    appConfig: {
        "okex-auto-trade": Object.assign({}, commonAppConfig, {
            namespace: 'okex',
            version: '1.0.0',
            description: 'okex auto trade',
            match: isProductionEnv ? `https://www.okex.com/**/*` : `${baseUrl}okex-auto-trade/**/*`,
            resources: [
                {
                    key: 'frm-okex-c2c-setting',
                    val: `${okexHtmlTmplPath}frm-okex-c2c-setting.html?t=${dateNow}`
                },
                {
                    key: 'frm-okex-spot-setting',
                    val: `${okexHtmlTmplPath}frm-okex-spot-setting.html?t=${dateNow}`
                },
                // {
                //     key: 'okexWebSocket',
                //     val: `${baseUrl}res/okex/external/js/websocket.js?t=${dateNow}`
                // },
            ],
        }),
        "kad-sync-manage": Object.assign({}, commonAppConfig, {
            match: `${baseUrl}kad-sync-manage/**/*`
        }),
    },
    baseUrl: baseUrl,
    layuiJsPath: layuiJsPath,
    layuiCssPath: layuiCssPath,
    layuiBasePath: layuiBasePath,
    getOkexWebSocketUrl: getOkexWebSocketUrl,
};

module.exports = userConfig;